<template>
	<!-- 评价evaluation -->
	<view>
		<u-navbar title="商品评价" :autoBack="true" :placeholder="true"></u-navbar>
		<view class="evaluation">
			<view class="evaluation-top">
				<text>星级评分</text>
				<u-rate v-model="form.com_level" allowHalf active-color="#806EFE" inactive-color="#F0F2F5">
				</u-rate>
			</view>
			<view class="evaluation-textarea">
				<u--textarea v-model="form.com_text" border="none" placeholder="描述商品使用感受" autoHeight></u--textarea>
			</view>
			<ImgUpload @callback="imgCallback" />
		</view>
		<view class="fixedBox">
			<view class="fixedBox-item" @click="messorder">
				立即评价
			</view>
		</view>
	</view>

</template>

<script>
	import code from 'uview-ui/libs/config/props/code';
	import ImgUpload from '../../components/ImgUpload/ImgUpload.vue'
	export default {
		data() {
			return {
				form: {
					order_id: null, //订单ID
					com_level: null, //星级
					com_text: "", //内容
					com_images: "", //图片
				},
				imgList: []
			};
		},
		components: {
			ImgUpload
		},
		onLoad(option) {
			this.form.order_id = option.id
			// console.log(option)
		},
		methods: {
			imgCallback(e) {
				if (e.length) {
					this.form.com_images = e.map(item => item.url).join(',')
				}
			},
			async messorder() {
				if (this.form.com_level == null || this.com_text == "") {
					this.$u.toast('请补全评论或评分')
				} else {
					let res = await this.$api.messorder(this.form)
					this.$u.toast(res.msg)
					if (res.code === 1) {
						let pages = getCurrentPages();
						let prevPage = pages[pages.length - 2];
						setTimeout(() => {
							if (prevPage.route == 'subPages/orderDetails/orderDetails') {
								uni.navigateBack({
									delta: 2
								});
							} else {
								uni.navigateBack()
							}
						}, 1000)
					}
				}
				// console.log(res);
			}
		}
	}
</script>
<style>
	page {
		background: #fff;
	}

	.u-textarea {
		background-color: #F8F9FE !important;
	}
</style>

<style lang="scss" scoped>
	.evaluation {
		box-sizing: border-box;
		padding: 24rpx;

		&-top {
			text {
				margin-right: 20rpx;
				color: rgba(0, 0, 0, 0.8);
				font-size: 28rpx;
				font-weight: 500;
			}

			display: flex;
		}

		&-textarea {
			margin: 36rpx 0;
			width: 686rpx;
			border-radius: 24rpx;
			opacity: 1;
			background: #F8F9FE;
			padding: 20rpx 28rpx;
			box-sizing: border-box;
		}
	}

	.fixedBox {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 188rpx;
		background-color: #fff;
		box-sizing: border-box;
		padding: 16rpx 32rpx 0 32rpx;
		border-top: 1rpx solid rgba(195, 195, 195, 0.2);

		&-item {
			text-align: right;
			width: 100%;
			height: 80rpx;
			border-radius: 80rpx;
			background: linear-gradient(131.2deg, rgba(179, 142, 255, 1) 0%, rgba(130, 111, 255, 1) 100%);
			line-height: 80rpx;
			text-align: center;
			color: rgba(255, 255, 255, 1);
			font-size: 28rpx;
			font-weight: 600;
		}
	}
</style>
